<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
	 <meta charset="utf-8">
	 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	 <title th:replace="common/base::pagetitle"></title>
	 <link th:replace="common/base::static"/>
</head>
<body style="background-color: #f2f2f2;">

<div id="kPage" class="layui-fluid" style="padding: 0">
	 <div class="layui-row">
		  <!-- 主要内容块 -->
		  <div class="layui-col-md12" id="kMainContentCol">
				<div class="layui-fluid wlb-fluid-padding15">
					 <div class="layui-card">
						  <form>
								<div class="layui-form layui-card-header wlb-card-header-auto">
									 <div class="layui-form-item">
										  <div class="layui-inline">
												<label class="layui-form-label">签章流程id</label>
												<div class="layui-input-inline">
													 <input type="text" name="flowId" placeholder="请输入" autocomplete="off" class="layui-input">
												</div>
										  </div>
										  <div class="layui-inline">
												<button class="layui-btn " lay-submit="" lay-filter="kTableSearchFilter">
													 <i class="layui-icon layui-icon-search"></i>
												</button>
												<button class="layui-btn " type="reset">
													 <i class="layui-icon layui-icon-refresh-1"></i>
												</button>
										  </div>
									 </div>
								</div>
						  </form>

						  <div class="layui-card-body">
								<table id="kContentTable" lay-filter="kContentTable"></table>
						  </div>
					 </div>

				</div>
		  </div>
	 </div>
</div>

<script th:replace="common/base::context"></script>
<script th:replace="common/base::mainjs"></script>

<script type="text/html" id="flowStatusTpl">
	 {{#  if(d.flowStatus == '0'){ }}
	 <span class="layui-badge layui-bg-blue">草稿</span>
	 {{#  } else if(d.flowStatus == '1') { }}
	 <span class="layui-badge">签署中</span>
	 {{#  } else if(d.flowStatus == '2') { }}
	 <span class="layui-badge layui-bg-green">完成</span>
	 {{#  } else if(d.flowStatus == '3') { }}
	 <span class="layui-badge">撤销</span>
	 {{#  } else if(d.flowStatus == '5') { }}
	 <span class="layui-badge">过期</span>
	 {{#  } else if(d.flowStatus == '7') { }}
	 <span class="layui-badge">拒签</span>
	 {{#  } else { }}
	 <span class="layui-badge layui-bg-gray">未知</span>
	 {{# } }}
</script>

<!--头部工具栏模板-->
<script type="text/html" id="headToolbarTpl">
</script>

<!--表格行工具栏模板-->
<script type="text/html" id="rowToolbarTpl">
	 <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>详情</a>
	 <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="signers"><i class="layui-icon layui-icon-friends"></i>签署列表</a>
	 {{#  if(d.flowStatus == '2'){ }}
	 <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="check"><i class="layui-icon layui-icon-find-fill"></i>查证</a>
	 <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="down"><i class="layui-icon layui-icon-find-fill"></i>下载文档</a>
	 {{# } }}
</script>

<script type="text/javascript" th:inline="javascript">
    layui.use(['element', 'form', 'layer', 'table'], function () {
        var elemet = layui.element, form = layui.form, layer = layui.layer, table = layui.table;
        var tableId = 'kContentTable';

        // 实例化table
        var tableIns = table.render($.extend(config.layui.table, {
            elem: '#' + tableId
            , url: BASE_WEB + 'esign/query/list/data' //数据接口
            , toolbar: '#headToolbarTpl'
            , cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                , {field: 'flowId', title: '流程ID', width: 100}
                , {field: 'fileId', title: '文件id', width: 100}
                , {field: 'url', title: '签章地址',  width: 180}
                , {field: 'shortUrl', title: '签章地址短链接',  width: 180}
                , {field: 'flowStatus', title: '签署状态', width: 120, templet: '#flowStatusTpl'}
                , {field: 'createDate', title: '创建时间', sort: true, width: 150}
                , {field: 'updateDate', title: '更新时间', sort: true, width: 150}
                , {field: '', title: '操作', width: 325, fixed: 'right', templet: '#rowToolbarTpl'}
            ]]
        }));

        var area = ['449px', '530px'];


        // 表格行按钮 监听事件
        table.on('tool(' + tableId + ')', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if (layEvent === 'del') {
                layer.confirm('确定删除吗？', function (index) {

                    //执行 Ajax 后重载
                    $.ajax({
                        type: req.type.post,
                        url: api.sys.userRm + data.id,
                        async: false,
                        success: function (r) {
                            if (r.code === req.status.ok) {
                                table.reload(tableId);
                                wlbKit.sucessMsg('已删除');
                            } else {
                                wlbKit.errorMsg(r.msg);
                            }
                        }
                    });
                });
            }
            if (layEvent === 'edit') {
                layer.open({
                    type: 2
                    , title: '签章详情'
                    , content: BASE_WEB + 'esign/query/detail?flowId=' + data.flowId
                    , maxmin: true
                    , area: area   // 宽高
                    , btn: ['关闭']
						  , end: function (){
                        table.reload(tableId);
						  }
                });
            }

            if (layEvent === 'signers') {
                layer.open({
                    type: 2
                    , title: '签章人列表'
                    , content: BASE_WEB + 'esign/query/getSignersView?flowId=' + data.flowId
                    , maxmin: true
                    , area: ['80%', '50%']   // 宽高
                    , btn: ['关闭']
                    , end: function (){
                        table.reload(tableId);
                    }
                });
            }

            if (layEvent === 'check') {
                layer.open({
                    type: 2
                    , title: '查证上链信息'
                    , content: BASE_WEB + 'esign/query/checkView?flowId=' + data.flowId
                    , maxmin: true
                    , area: ['80%', '50%']   // 宽高
                    , btn: ['关闭']
                    , end: function (){
                        table.reload(tableId);
                    }
                });
            }

            if (layEvent === 'down') {
                wlbKit.get(BASE_WEB + 'esign/query/downFlowDoc?flowId=' + data.flowId, null, function (r) {
                    if (r.code === req.status.ok) {
                        console.log(JSON.stringify(r.data))
                        $(r.data.docs).each(function (i,o){
                            window.open(o.fileUrl);
								})
                    } else {
                        wlbKit.errorMsg(r.msg);
                    }
					 });
            }

        });

        // 监听查询
        form.on('submit(kTableSearchFilter)', function (obj) {
            var params = obj.field;
            log('seach=', params);//
            tableIns.reload({
                where: params,
                page: {curr: 1}
            });
            return false;
        });

        // 绑定监听回车事件
        wlbKit.bindEnterEventForLayuiForm();

    });
</script>

</body>
</html>
